package com.msb.service.impl;

import com.msb.service.PicService;
import com.msb.utils.FastDFSClient;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

@Service
public class PicServiceImpl implements PicService{
    @Override
    public Map<String, Object> upload(MultipartFile file) {

        Map<String ,Object> map = new HashMap<>();

        try{
            String[] result = FastDFSClient.uploadFile(file.getInputStream() , file.getOriginalFilename());

            map.put("error" , 0 );
            map.put("url" , "http://192.168.93.10:8888/"+ result[0] +"/"+ result[1]);

            return map;

        }catch (Exception e)
        {
            e.printStackTrace();
        }
        map.put("error" , 1 );
        map.put("message" , "上传失败！");

        return map;
    }
}
